<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>商品信息管理</title>
	</head>
	<body>
		<center>
			<h3>编辑商品信息</h3>
			<?php
				require("../../public/config.php");//导入配置文件
				//连接数据库
				$link = mysqli_connect(HOST,USER,PASS,DBNAME) or die("连接数据库失败！");
				mysqli_set_charset($link,"utf8");//设置编码格式
				$sql = "select * from goods where id=".$_GET['id'];	//查询数据
				$result = mysqli_query($link,$sql);//发送sql语句并获取结果集
				if(mysqli_num_rows($result)){
					$goods = mysqli_fetch_assoc($result);//输出结果集
					mysqli_free_result($result);
				}else{
					echo "没有要修改的数据！";
				}
				mysqli_close($link);
			?>
			<table width="380" border="1">
				<form action="action.php?a=update" method="post" enctype="multipart/form-data">
					<input type="hidden" name="id" value="<?php echo $goods['id'];?>">
					<input type="hidden" name="oldpicname" value="<?php echo $goods['picname'];?>">
					<table width="380" border="0">
					<tr>
			 			<td align="right">商品类别</td>
			 			<td>
			 				<select name="typeid">
								<?php 
									//1.导入配置文件
									require("../../public/config.php");
									//2.连接数据库
									$link = @mysqli_connect(HOST,USER,PASS,DBNAME) or die("连接数据库失败");
									//3.字符集
									mysqli_set_charset($link,"utf8");
									//4.定义sql语句 发送执行
									$sql = "select * from type order by concat(path,id)";
									$result = mysqli_query($link,$sql);
									//5.解析结果集
									while($row = mysqli_fetch_assoc($result)){
										$m = substr_count($row['path'],",")-1;//逗号出现的次数
										$str = str_repeat("&nbsp",$m*2);//输出空格
										//判断是否禁用
										$disabled = ($row['pid']==0)?"disabled":"";
										//判断是否选中
										$selected = ($row['id'] == $goods['typeid'])?"selected":"";
										echo "<option {$selected} {$disabled} value='{$row['id']}'>";
										echo "{$str}|--{$row['name']}";
										echo "</option>";
									}
								 ?>
							</select>
			 			</td>
			 		</tr>
					<tr>
			 			<td align="right">商品名称</td>
			 			<td><input type="text" name="goods" value="<?php echo $goods['goods']; ?>"></td>
			 		</tr>
			 		<tr>
			 			<td align="right">生产厂家</td>
			 			<td><input type="text" name="company" value="<?php echo $goods['company']; ?>"></td>
			 		</tr>
			 		<tr>
			 			<td align="right">商品图片</td>
			 			<td><input type="file" name="pic"></td>
			 		</tr>
			 		<tr>
			 			<td align="right">单价</td>
			 			<td><input type="text" name="price" value="<?php echo $goods['price'];?>"></td>
			 		</tr>
			 		<tr>
			 			<td align="right">库存量</td>
			 			<td><input type="text" name="store" value="<?php echo $goods['store']; ?>"></td>
			 		</tr>
			 		<tr>
			 			<td align="right">状态</td>
			 			<td>
			 				<input type="radio" name="state" <?php echo ($goods['state']==1)?"checked":""; ?> value="1">新商品
			 				<input type="radio" name="state" <?php echo ($goods['state']==2)?"checked":""; ?> value="2">在售
			 				<input type="radio" name="state" <?php echo ($goods['state']==3)?"checked":""; ?> value="3">已下架
			 			</td>
			 		</tr>
			 		<tr>
			 			<td align="right">描述</td>
			 			<td><textarea cols="30" rows="5" name="descr"><?php echo $goods['descr']; ?></textarea></td>
			 		</tr>
			 		<tr>
			 			<td colspan="2" align="center">
			 				<input type="submit" value="提交">
			 				<input type="reset" value="重置">
			 			</td>
			 		</tr>
				</form>
			</table>
		</center>
	<body>
</html